package com.ygqh.baby.task;

import com.ygqh.baby.service.task.*;
import com.ygqh.baby.utils.DateConvertUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component("taskJob")
public class TaskHandler {
    @Autowired
    private YgTaskService taskSevice;
    @Autowired
    private YgBiTaskService ygBiTaskService;
    @Autowired
    private YgLSTaskService yglsTaskService;
    @Autowired
    private YgWdtTaskService ygWdtTaskService;
    @Autowired
    private YgMonitoringService ygMonitoringService;
    @Value("${channel.scan.limit_time}")
    private String channel_scan_limit_time;
    @Value("${orderStatus4Send.limit_time}")
    private String orderStatus4Send_limit_time;
    @Value("${syncStockOrderTask.limit_time}")
    private String syncStockOrderTask_limit_time;
    @Value("${orderPushTask.limit_time}")
    private String timeInterval;
    @Autowired
    private YgNgmmTaskService ygNgmmTaskService;
    @Autowired
    private YgBalanceTaskService ygBalanceTaskService;
    @Autowired
    private YgCouponTaskService ygCouponTaskService;
    @Autowired
    private YgSubscribeTaskService ygSubscribeTaskService;
    @Autowired
    private YgProductSecondTaskService ygProductSecondTaskService;
    @Autowired
    private WxMsgTaskService wxMsgTaskService;
    @Autowired
    private YgGroupBuyTaskService ygGroupBuyTaskService;
    @Autowired
    private YgProductBookTaskService ygProductBookTaskService;
    @Autowired
    private YgSearchWordTaskService ygSearchWordTaskService;
    @Autowired
    private YgUserTaskService ygUserTaskService;
    @Autowired
    private YgWdtSkuTaskService ygWdtSkuTaskService;

    /**
     * 商品上下架任务
     */
    public void productStatusTask() {
        taskSevice.productStatusTask();
    }

    /**
     * 订单自动取消任务
     */
    public void orderStatusForCancelTask() {
        taskSevice.orderStatusForCancelTask();
    }

    /**
     * 订单返利任务
     */
    public void balanceTask() {
        Date date = new Date();
        if (date.after(DateConvertUtils.parse("2018-01-01", DateConvertUtils.DATE_FORMAT))) {
            return;
        }
        taskSevice.balanceTask(5);
    }

    /**
     * 发送支付邀请任务
     */
    public void sendPayInvitation() {

        taskSevice.sendPayInvitation();
    }

    /**
     * 订单发货7天后自动完成任务
     */
    public void orderStatusForSuccessTask() {

        taskSevice.orderStatusForSuccessTask();
    }

    /**
     * 交易成功后7天如果用户没有评论，系统自动好评
     */
    public void productCommentTask() {

        taskSevice.productCommentTask();
    }

    /**
     * 30天后预收入金额转换成可提现金额
     */
    public void preIncomeToBalance() {
        taskSevice.preIncomeToBalance();
    }

    /**
     * 同步出入库数据到本地
     */
    public void channelScan() {

        ygBiTaskService.channelScan(Integer.parseInt(channel_scan_limit_time));
    }

    /**
     * 每日渠道统计
     */
    public void statisticsChannelByDay() {

        ygBiTaskService.statisticsChannelByDay();
    }

    /**
     * 每日订单统计
     */
    public void statisticsOrderByDay() {

        ygBiTaskService.statisticsOrderByDay();
    }
    public void statisticsOrderNew() {
        ygBiTaskService.statisticsOrderNew();
    }

    /**
     * 每日用户统计
     */
    public void calculateAddedUsers() {
        taskSevice.calculateAddedUsers();
    }

    /**
     * 更新商品销售量和评论数量
     */
    public void updateProductSaleNumAndCommentNum() {
        taskSevice.updateProductSaleNumAndCommentNum();
    }

    /**
     * 退换货单自动完成
     */
    public void returnOrderForCompleteTask() {
        taskSevice.returnOrderForCompleteTask();
    }

    /**
     * 退换货单自动取消
     */
    public void returnOrderForCancelTask() {
        taskSevice.returnOrderForCancelTask();
    }

    /**
     * 好友通过用户分享的链接注册并下单支付成功的第1单（发货15天没发生退货/取消订单）给用户20元红包余额（分享红包）
     */
    public void sendRedPacket() {
        taskSevice.sendRedPacket();
    }

    /**
     * 每日把员工钱转到老板账号
     */
    public void employeeToEmployer() {
        taskSevice.employeeToEmployer();
    }

    /**
     * 推送什么值得买订单
     */
    public void lsOrderPushTask() {
        yglsTaskService.orderPushTask(5);
    }

    /**
     * 联盟用户订单报表
     */
    public void affiliateUserReport() {
        taskSevice.affiliateUserReport();
    }

    /**
     * 成长基金到账提醒
     */
    @Deprecated
    public void sendGrowthFundMsg() {
        taskSevice.sendGrowthFundMsg();

    }

    /**
     * 拼团订单未完成提醒（一小时）
     */
    public void groupOrderIncompleteReminder() {
        taskSevice.groupOrderIncompleteReminder();
    }

    /**
     * 拼团完成
     */
    public void groupOrderComplete() {
        taskSevice.groupOrderComplete();
    }

    public void syncLogistics() {
        ygWdtTaskService.syncLogistics(5);
    }

    public void syncOrder() {
        ygWdtTaskService.syncOrder(5);
    }

    public void syncSkuStock() {
        ygWdtTaskService.syncSkuStock();
    }

    public void syncStockIn() {
        ygWdtTaskService.syncStockIn(60);
    }

    public void syncStockOut() {
        ygWdtTaskService.syncStockOut(60);
    }

    /**
     * 监控未同步的订单，
     *
     * @param 入参
     * @return void 返回类型
     * @throws @date 2017年6月30日 上午11:37:21
     * @Title: syncStockOuts
     * @author （guohao）
     * @version V1.0
     */
    public void monitorPushOrderToWDT() {
        taskSevice.monitorPushOrderToWDT();
    }

    public void monitoringSystem() {
        ygMonitoringService.monitoringSystem();
    }

    public void checkStock() {
        ygMonitoringService.checkStock();
    }

    public void sendMallWithOrderExpress() {
        ygMonitoringService.sendMallWithOrderExpress(38L,
                "guohao@yiigoo.com,gushashan@nicomama.com,wanghui@nicomama.com,yuwenjun@nicomama.com,guowei@yiigoo.com");
        ygMonitoringService.sendMallWithOrderExpress(39L, "guohao@yiigoo.com,haobo@lafaso.com,guowei@yiigoo.com");
    }

    public void sendKanJiaInvitation() {
        taskSevice.sendKanJiaInvitation();
    }

    public void loadWdtOrder() {
        ygWdtTaskService.loadWdtOrder(30);

    }

    public void sendPreSaleForRemind() {
        ygBiTaskService.sendPreSaleForRemind();

    }

    public void statisticalSkuSaleCount() {
        ygBiTaskService.statisticalSkuSaleCount();

    }

    public void statisticsWdtOrder() {
        ygBiTaskService.statisticsWdtOrder();

    }

    public void sendCoupon1111() {
        Date limitDate = DateConvertUtils.parse("2017-11-11", DateConvertUtils.DATE_FORMAT);
        taskSevice.sendCoupon1111(limitDate);

    }

    /**
     * 同步年糕妈妈订单，一小时执行一次
     */
    public void loadNgmmOrder() {
        ygNgmmTaskService.loadNgmmOrder(60);
    }

    /**
     * 订单返利任务
     */
    public void balanceTaskV2() {
        ygBalanceTaskService.preBalanceTask();

    }

    public void affiliateUserReportV2() {
        ygBalanceTaskService.affiliateUserReport();

    }

    public void checkBalanceToBalanceTask() {
        ygBalanceTaskService.checkBalanceToBalanceTask();

    }

    public void calculateExtraRewards() {
        ygBalanceTaskService.calculateExtraRewards();

    }

    /**
     * 新用户下单，反赠推荐用户优惠券
     */
    public void giveCouponToForeverUser() {
        ygCouponTaskService.giveCouponToForeverUser();
    }

    /**
     * 秒杀通知提醒
     */
    public void sendSubscribeMsg() {
        ygSubscribeTaskService.sendSubscribeMsg();
    }

    /**
     * 秒杀活动更新商品销售价
     */
    public void changeProductPriceBySecond() {
        ygProductSecondTaskService.changeProductPriceBySecond();
    }

    /**
     * 发送微信客服图文消息
     */
    public void sendCustomerNewsMsg() {
        wxMsgTaskService.sendCustomerNewsMsg();
    }

    /**
     * 每日统计品牌订单数据
     */
    public void statisticsSupplierOrderByDay() {
        ygBiTaskService.statisticsSupplierOrderByDay();
    }

    /**
     * 统计新世界品牌订单数据
     */
    public void statisticsSupplierOrderByDayFromKids() {
        ygBiTaskService.statisticsSupplierOrderByDayFromKids();
    }

    /**
     * 每日统计新世界订单数据
     */
    public void statisticsOrderFromKids() {
        ygBiTaskService.statisticsOrderFromKids();
    }

    public void groupOrderIncompleteReminderV2() {
        ygGroupBuyTaskService.groupOrderIncompleteReminder();
    }

    public void groupOrderCompleteV2() {
        ygGroupBuyTaskService.groupOrderComplete();
    }

    /**
     * 生成代理邀请码
     */
    public void generateInviteCode() {
        ygBalanceTaskService.generateInviteCode();
    }

    public void notPassCultivationByMonth() {
        ygBalanceTaskService.notPassCultivationByMonth();
    }

    /**
     * 新用户下单，反赠推荐用户卡券
     */
    public void giveCardCouponToOrderSource() {
        ygCouponTaskService.giveCardCouponToOrderSource();
    }

    /**
     * 卡券到期提醒（10天、20天后到期）
     */
    public void remindCardCouponOver() {
        ygCouponTaskService.remindCardCouponOver();
    }

    /**
     * 定时取消活动记录
     */
    public void cancelRecod() {
        ygProductBookTaskService.cancelRecod();
    }

    /**
     * 搜索词检查
     */
    public void checkSearchWord() {
        ygSearchWordTaskService.checkSearchWord();
    }

    /**
     * 检查促销标记服务
     */
    public void checkPromotionTag() {
        ygMonitoringService.checkPromotionTags();
    }

    /**
     * 优惠券过期提醒
     */
    public void remindCouponOver() {
        ygCouponTaskService.remindCouponOver();
    }

    /**
     * 女王过期提醒
     */
    public void checkVipUserValid() {
        ygUserTaskService.checkVipUserValid();
    }

    /**
     * 同步所有SKU库存
     */
    public void syncAllSkuStock() {
        ygWdtSkuTaskService.syncAllSkuStock();
    }

    /**
     * 统计旺店通销售数据并发送邮件
     */
    public void sendWDTSalesReportMail() {
        ygWdtSkuTaskService.sendWDTSalesReportMail();
    }
}
